<template>
    <div class="app-container">
        <section>
            <div class="contentBox">
                <div class="title">
                    <span>{{$route.query.title}}</span>
                </div>
                <div class="content">
                    <el-form ref="form"  :model="form"  class="form"  label-width="110px" :rules="rules">
                        <el-form-item label="分享项目"  style="width:100%" prop="project_id">
                              <el-select v-model="form.project_id" placeholder="请选择"> 
                                <el-option
                                v-for="item in options"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="分享人积分"  style="width:100%" prop="share_integral">
                            <el-input v-model="form.share_integral" placeholder="请输入"></el-input>
                        </el-form-item>
                        <el-form-item label="被分享人积分"  style="width:100%" prop="be_share_integral">
                            <el-input v-model="form.be_share_integral"  placeholder="请输入"></el-input>
                        </el-form-item>
                    </el-form>
                    <div style="margin-top:40px">
                        <el-button style="width:143px" @click="$router.go(-1)">取消</el-button>
                        <el-button type="primary" style="width:143px" @click="save">保存</el-button>
                    </div>
                </div>
            </div>
        </section>
    </div>
</template>
<script>
export default {
    data() {
        return {
            value1:false,
            options: [],
            value: '',
            list:[{}],
            form: {
                project_id:'',
                share_integral:'',
                be_share_integral:'',
                id:'',
            },
            rules: {
                project_id: [
                    { required: true, message: '请选择项目', trigger: 'change' },
                ],
                share_integral: [
                    { required: true, message: '请输入分享人积分', trigger: 'blur' },
                ],
                be_share_integral: [
                    { required: true, message: '请输入被分享人积分', trigger: 'blur' },
                ]
            },
            roleList: []
        }
    },
    created() {
        if (this.$route.query.id) {
            this.form.id = this.$route.query.id
            this.getDetails()
        }
        this.repairGetList()
        this.$route.meta.title = this.$route.query.title
    },
    methods: {
        async getDetails(){
            let { code, data } = await this.$Http.infoShareIntegral({id:this.form.id});
            if (code) {
                this.form={
                    project_id:data.project_id,
                    share_integral:data.share_integral,
                    be_share_integral:data.be_share_integral,
                    id:this.$route.query.id
              }
            }
        },
         async repairGetList() {
            let { code, data } = await this.$Http.getProject({is_all:1});
            if (code) {
                data.forEach((ele,index)=>{
                    let obj = {
                     value: ele.id,
                     label: ele.name
                    }
                    this.options.push(obj)
                })
               
            }
        },
        save() {
            this.$refs.form.validate(async (valid) => {
                if (valid) {
                   let { code, data } = await this.$Http.setShareIntegral(this.form)
                    if (code) {
                        if(this.form.id){
                           this.$message.success('编辑成功')
                        }else{
                           this.$message.success('添加成功')
                        }
                        this.$router.go(-1)
                    }
                } else {
                    return false;
                }
            });
        },
    }
}
</script>

<style lang="scss" scoped>
.app-container {
    section {
        .contentBox {
            background: #fff;
            border-radius: 8px;
            padding: 0px 24px 20px;
            min-width: 900px;
            min-height: calc(100vh - 165px );
            .title {
                line-height: 70px;
                font-size: 18px;
                font-weight: 600;
                color: #383b40;
                .el-icon-close {
                    cursor: pointer;
                }
            }
        }
        .content {
            max-width:800px;
            height: 100%;
            .form {
                display: flex;
                flex-wrap: wrap;
                justify-content: space-between;
            }
        }
    }
}
::v-deep{
    .el-input,.el-select{
        width: 250px;
    }
    .el-icon-circle-plus-outline,.el-icon-remove-outline{
        color: #999;
        font-size: 26px;
        margin: 0 5px;
    }
     .el-icon-circle-plus-outline{
        margin-left: 20px;
    }
    .el-icon-remove-outline{
        color: #f00;
    }
    .el-form-item__content{
        display: flex;
        align-items: center;
    }
}
</style>